var o, e = require, t = module, n = exports, i = this && this.__extends || (o = function(e, t) {
    return (o = Object.setPrototypeOf || {
        __proto__: []
    } instanceof Array && function(e, t) {
        e.__proto__ = t;
    } || function(e, t) {
        for (var i in t) t.hasOwnProperty(i) && (e[i] = t[i]);
    })(e, t);
}, function(e, t) {
    function i() {
        this.constructor = e;
    }
    o(e, t), e.prototype = null === t ? Object.create(t) : (i.prototype = t.prototype, 
    new i());
}), a = this && this.__decorate || function(e, t, i, s) {
    var a, n = arguments.length, r = n < 3 ? t : null === s ? s = Object.getOwnPropertyDescriptor(t, i) : s;
    if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(e, t, i, s); else for (var o = e.length - 1; 0 <= o; o--) (a = e[o]) && (r = (n < 3 ? a(r) : 3 < n ? a(t, i, r) : a(t, i)) || r);
    return 3 < n && r && Object.defineProperty(t, i, r), r;
};

Object.defineProperty(n, "__esModule", {
    value: !0
});

var r = e("Global"), s = e("AudioManager"), c = e("DailyItemView"), l = e("TimeView"), d = e("PersonView"), u = e("PopItemView"), p = e("PetManager"), h = e("GameConfig"), f = e("GameData"), g = e("DataManager"), m = e("WebManager"), y = e("LoadManager"), v = e("UIManager"), w = cc._decorator, b = w.ccclass, P = w.property, I = function(t) {
    function e() {
        var e = null !== t && t.apply(this, arguments) || this;
        return e.btns = null, e.already = null, e.getBtn = null, e.layout = null, e.right = null, 
        e.warn = null, e.personView = null, e.timeView = null, e.nameSprite = null, e.infoSprite = null, 
        e.titleSprite = null, e.titleLabel = null, e.numLabel = null, e.subscribeBtn = null, 
        e.items = [], e.startIdx = 0, e.petDailyIdx = 10, e.skinDailyIdx = 10, e.dragonDailyIdx = 10, 
        e.idx = 0, e;
    }
    return i(e, t), e.prototype.onLoad = function() {
        var e, t;
        v.default.getInstance().hidePnl("start"), this.items = this.layout.getComponentsInChildren(c.default), 
        5 <= f.GD.dailyInfo.length && f.GD.dailyInfo.filter(function(e, t) {
            return t < 5;
        }).every(function(e) {
            return 1 == e;
        }) ? (0 == f.GD.dailyLastTime && (f.GD.dailyLastTime = Date.now()), this.startIdx = 5, 
        y.default.getInstance().loadSpriteFrame({
            url: "image/ui/签到文字2@2x",
            sprite: this.titleSprite
        }), e = new Date(f.GD.dailyLastTime), t = new Date(f.GD.dailyLastTime + 14 * r.G.ONE_DAY_TIME), 
        this.titleLabel.string = "活动时间：" + e.getFullYear() + "." + (e.getMonth() + 1) + "." + e.getDate() + "-" + t.getFullYear() + "." + (t.getMonth() + 1) + "." + t.getDate()) : (y.default.getInstance().loadSpriteFrame({
            url: "image/ui/签到文字@2x",
            sprite: this.titleSprite
        }), this.titleLabel.node.active = !1);
        for (var i = this.startIdx; i < this.startIdx + 5; i++) {
            var s, a = i - this.startIdx;
            a < this.items.length && i < h.GC.dailyRewardList.length && (this.items[a].refresh(h.GC.dailyRewardList[i]), 
            h.GC.dailyRewardList[i].type == r.RewardType.PET || h.GC.dailyRewardList[i].type == r.RewardType.SKIN || h.GC.dailyRewardList[i].type == r.RewardType.DRAGON) && ((s = cc.instantiate(this.warn)).parent = this.items[a].node, 
            s.setPosition(cc.v2(60, 80)));
        }
        for (i = 0; i < h.GC.dailyRewardList.length; i++) i < this.petDailyIdx && h.GC.dailyRewardList[i].type == r.RewardType.PET && (this.petDailyIdx = i), 
        i < this.skinDailyIdx && h.GC.dailyRewardList[i].type == r.RewardType.SKIN && (this.skinDailyIdx = i), 
        i < this.dragonDailyIdx && h.GC.dailyRewardList[i].type == r.RewardType.DRAGON && (this.dragonDailyIdx = i);
    }, e.prototype.onEnable = function() {
        GA.isToday(f.GD.signLastTime) ? (this.btns.active = !1, this.already.active = !0, 
        this.numLabel.node.parent.active = !1) : (this.btns.active = !0, this.already.active = !1), 
        this.refresh();
        var e = h.GC.dailyRewardList[this.idx];
        e && (!GA.isByteDance() && r.G.platform != r.Platform.XiaoDu && (e.type == r.RewardType.PET || e.type == r.RewardType.SKIN || e.type == r.RewardType.DRAGON) ? this.getBtn.node.active = !1 : this.getBtn.node.active = !0);
    }, e.prototype.onDestroy = function() {
        v.default.getInstance().releasePnl(this.text), v.default.getInstance().showPnl("start");
    }, e.prototype.onClickGet = function() {
        var i = this;
        this.pushEvent("普通领取"), GA.isByteDance() && GA.PA && GA.PA.requestSubscribeMessage && 0 < r.G.subscribeTmplIds.length && (1 == h.GC.subscribeType || 3 == h.GC.subscribeType) ? (this.pushEvent("订阅"), 
        GA.PA.requestSubscribeMessage({
            tmplIds: r.G.subscribeTmplIds,
            success: function(t) {
                var e = r.G.subscribeTmplIds.filter(function(e) {
                    return "accept" == t[e];
                });
                0 < e.length && (m.default.getInstance().sentLog("订阅成功"), i.doSubscribe(e));
            },
            complete: function() {
                i.doGet();
            }
        })) : this.doGet();
    }, e.prototype.onClickBack = function() {
        s.default.getInstance().playAudio("按钮2"), this.pushEvent("返回"), this.hidePnl();
    }, e.prototype.onClickSubscribe = function() {
        var i = this;
        s.default.getInstance().playAudio("按钮2"), GA.isWeChat() || GA.isByteDance() ? (this.pushEvent("订阅"), 
        GA.PA.requestSubscribeMessage({
            tmplIds: r.G.subscribeTmplIds,
            success: function(t) {
                var e = r.G.subscribeTmplIds.filter(function(e) {
                    return "accept" == t[e];
                });
                0 < e.length && (m.default.getInstance().sentLog("订阅成功"), i.doSubscribe(e));
            }
        })) : GA.isQQ() && (this.pushEvent("订阅"), GA.PA.subscribeAppMsg({
            subscribe: !0,
            success: function() {
                i.doSubscribe();
            }
        }));
    }, e.prototype.doGet = function(e) {
        void 0 === e && (e = 1), !GA.isToday(f.GD.signLastTime) && this.idx < h.GC.dailyRewardList.length ? (this.getReward(this.idx, e) && (s.default.getInstance().playAudio("获得钻石"), 
        f.GD.sign(this.idx), g.default.getInstance().save(), this.btns.active = !1, this.already.active = !0, 
        this.numLabel.node.parent.active = !1, this.scheduleOnce(this.hidePnl, 5)), this.refresh()) : (this.btns.active = !1, 
        this.already.active = !0, this.numLabel.node.parent.active = !1, this.scheduleOnce(this.hidePnl, 5));
    }, e.prototype.doSubscribe = function(e) {
        void 0 === e && (e = r.G.subscribeTmplIds), m.default.getInstance().subscribe({
            subscribe: 1,
            tmplIds: e,
            success: function() {
                console.log("subscribe success");
            }
        });
    }, e.prototype.callback = function() {
        var i = this;
        GA.isByteDance() && GA.PA && GA.PA.requestSubscribeMessage && 0 < r.G.subscribeTmplIds.length && (1 == h.GC.subscribeType || 3 == h.GC.subscribeType) ? (this.pushEvent("订阅"), 
        GA.PA.requestSubscribeMessage({
            tmplIds: r.G.subscribeTmplIds,
            success: function(t) {
                var e = r.G.subscribeTmplIds.filter(function(e) {
                    return "accept" == t[e];
                });
                0 < e.length && (m.default.getInstance().sentLog("订阅成功"), i.doSubscribe(e));
            },
            complete: function() {
                i.doGet(2);
            }
        })) : this.doGet(2);
    }, e.prototype.getReward = function(e, t) {
        if (void 0 === t && (t = 1), h.GC.dailyRewardList && e < h.GC.dailyRewardList.length) {
            var i = h.GC.dailyRewardList[e];
            switch (i.type) {
              case r.RewardType.DIAMOND:
                return i.num = i.num * t, f.GD.updateNumber("diamond", i.num), v.default.getInstance().loadPopPnl("reward", i), 
                !0;

              case r.RewardType.SKIN:
                return 0 == r.G.personModelList.filter(function(e) {
                    return e.id == i.idx;
                }).length || -1 < f.GD.skins.indexOf(i.idx) || (this.pushEvent("领取签到皮肤"), f.GD.addVideoCount(i.videoIdx), 
                !!f.GD.checkVideoCount(i.videoIdx) && (f.GD.hasSkin(i.idx) || f.GD.addSkin(i.idx), 
                f.GD.personIdx < i.idx && (f.GD.personIdx = i.idx), v.default.getInstance().loadPopPnl("reward", i), 
                m.default.getInstance().sentLog("获得签到皮肤"), !0));

              case r.RewardType.PET:
                return !!p.default.getInstance().isHas(0) || (this.pushEvent("领取机器狗宠物"), f.GD.addVideoCount(i.videoIdx), 
                !!f.GD.checkVideoCount(i.videoIdx) && (p.default.getInstance().getRealData(0).has = 1, 
                v.default.getInstance().loadPopPnl("reward", i), m.default.getInstance().sentLog("获得机器狗宠物"), 
                !0));

              case r.RewardType.PIECE:
                return i.num = i.num * t, f.GD.updateNumber("piece", i.num), v.default.getInstance().loadPopPnl("reward", i), 
                !0;

              case r.RewardType.DRAGON:
                return !!p.default.getInstance().isHas(1) || (this.pushEvent("领取机器龙宠物"), f.GD.addVideoCount(i.videoIdx), 
                !!f.GD.checkVideoCount(i.videoIdx) && (p.default.getInstance().getRealData(1).has = 1, 
                cc.systemEvent.emit("hatch_reward", !1), v.default.getInstance().loadPopPnl("reward", i), 
                m.default.getInstance().sentLog("获得机器龙宠物"), !0));

              default:
                return !1;
            }
        }
    }, e.prototype.refresh = function() {
        f.GD.dailyInfo.length == h.GC.dailyRewardList.length && f.GD.dailyInfo.every(function(e) {
            return 1 == e;
        }) && (this.btns.active = !1, this.already.active = !0, this.numLabel.node.parent.active = !1);
        for (var e = this.startIdx; e < this.startIdx + 5; e++) {
            e >= f.GD.dailyInfo.length && (f.GD.dailyInfo[e] = 0);
            var t = f.GD.dailyInfo[e], i = e - this.startIdx;
            if (!(0 < t)) {
                this.idx = e, GA.isToday(f.GD.signLastTime) ? 0 < i && (this.items[i - 1].showAlready(), 
                this.items[i].showCurrent()) : this.items[i].showCurrent();
                break;
            }
            i < this.items.length && (this.items[i].showAlready(), (t = cc.instantiate(this.right)).parent = this.items[i].node, 
            t.setPosition(cc.v2(0, -90)));
        }
        this.refreshInfo();
    }, e.prototype.refreshInfo = function() {
        if (f.GD.dailyInfo.length == h.GC.dailyRewardList.length && f.GD.dailyInfo.every(function(e) {
            return 1 == e;
        })) return this.showPet(h.GC.dailyRewardList[this.dragonDailyIdx].idx), void this.showName("image/ui/签到机甲暴龙字@2x");
        h.GC.dailyRewardList[this.idx] && (this.idx <= this.petDailyIdx ? p.default.getInstance().isHas(0) ? this.idx == this.petDailyIdx ? (f.GD.dailyInfo[this.idx] = 1, 
        g.default.getInstance().save(), this.refresh()) : (this.showPerson(10), this.showName("image/ui/签到暴走小妹字@2x")) : (this.showPet(h.GC.dailyRewardList[this.petDailyIdx].idx), 
        this.showTimer(this.petDailyIdx)) : this.idx < 5 ? (this.showPerson(10), this.showName("image/ui/签到暴走小妹字@2x")) : this.idx == this.dragonDailyIdx && p.default.getInstance().isHas(1) && 1 != f.GD.dailyInfo[this.idx] ? (f.GD.dailyInfo[this.idx] = 1, 
        g.default.getInstance().save(), this.refresh()) : (this.showPet(h.GC.dailyRewardList[this.dragonDailyIdx].idx), 
        this.showName("image/ui/签到机甲暴龙字@2x")));
    }, e.prototype.showPet = function(e) {
        this.infoSprite.node.active = !1, this.personView.node.active = !0, this.personView.initPet(e), 
        this.showInfo();
    }, e.prototype.showPerson = function(e) {
        this.infoSprite.node.active = !0, this.personView.node.active = !0, this.personView.init(e), 
        this.showInfo();
    }, e.prototype.showInfo = function() {
        h.GC.dailyRewardList[this.idx].type == r.RewardType.SKIN || h.GC.dailyRewardList[this.idx].type == r.RewardType.PET || h.GC.dailyRewardList[this.idx].type == r.RewardType.DRAGON ? (r.G.platform != r.Platform.XiaoDu && (this.btns.active && (this.numLabel.node.parent.active = !0), 
        this.numLabel.string = f.GD.subVideoCount(h.GC.dailyRewardList[this.idx].videoIdx).toString()), 
        this.myButton.init(this.text, "领 取")) : (this.numLabel.node.parent.active = !1, 
        this.myButton.init(this.text, "翻 倍"));
    }, e.prototype.showTimer = function(e, t) {
        void 0 === t && (t = this.idx), GA.PA && GA.PA.requestSubscribeMessage && 0 < r.G.subscribeTmplIds.length && (2 == h.GC.subscribeType || 3 == h.GC.subscribeType) && (this.subscribeBtn.node.active = !0), 
        this.nameSprite.node.active = !1, this.timeView.node.active = !0, GA.isToday(f.GD.signLastTime) && t--, 
        e <= t ? this.timeView.init(0) : (this.timeView.init(86400 * (e - t) - Math.floor(Date.now() / 1e3) + Math.floor(new Date().setHours(0, 0, 0, 0) / 1e3)), 
        this.timeView.startTimer());
    }, e.prototype.showName = function(e) {
        this.subscribeBtn.node.active = !1, this.nameSprite.node.active = !0, this.timeView.node.active = !1, 
        y.default.getInstance().loadSpriteFrame({
            url: e,
            sprite: this.nameSprite
        });
    }, a([ P(cc.Node) ], e.prototype, "btns", void 0), a([ P(cc.Node) ], e.prototype, "already", void 0), 
    a([ P(cc.Button) ], e.prototype, "getBtn", void 0), a([ P(cc.Node) ], e.prototype, "layout", void 0), 
    a([ P(cc.Node) ], e.prototype, "right", void 0), a([ P(cc.Node) ], e.prototype, "warn", void 0), 
    a([ P(d.default) ], e.prototype, "personView", void 0), a([ P(l.default) ], e.prototype, "timeView", void 0), 
    a([ P(cc.Sprite) ], e.prototype, "nameSprite", void 0), a([ P(cc.Sprite) ], e.prototype, "infoSprite", void 0), 
    a([ P(cc.Sprite) ], e.prototype, "titleSprite", void 0), a([ P(cc.Label) ], e.prototype, "titleLabel", void 0), 
    a([ P(cc.Label) ], e.prototype, "numLabel", void 0), a([ P(cc.Button) ], e.prototype, "subscribeBtn", void 0), 
    a([ b ], e);
}(u.default);

n.default = I;